package com.coke.spring.sentinel.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.coke.spring.sentinel.common.Order;
import com.coke.spring.sentinel.common.Product;
import com.coke.spring.sentinel.common.Result;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author cwm
 * @Description TODO
 * @date 2021/8/31 上午10:47
 * @Version 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @GetMapping("/find/{id}")
    public Result find(@PathVariable("id") String id){
        AtomicReference<Order> order =new AtomicReference<>();
        Order.orderList.stream().forEach(item ->{
            if (item.getId().equals(id)){
                order.set(item);
            }
        });
        String s = HttpUtil.get("localhost:9999/product/find/" + order.get().getProductId());
        return Result.ok(order.get()+":"+s);
    }

    @GetMapping("/hold")
    public String hold(@RequestParam("id") String id){
        System.out.println(id);
        return "xxxxx";
    }

    @GetMapping("/test-a")
    public String A(){
        return "test-a";
    }

    @GetMapping("/test-b")
    public String B(){
        return "test-b";
    }

}
